﻿using Lamex.Interface;
using Lamex.Library;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Lamex.mMachine.UI
{
    public partial class frmMAC_Equipment_Detail_State : frmBaseChild
    {
        DataTable dataTable = new DataTable();
        DataTable dataTable2 = new DataTable();
        string colums_xaxis;
        string colums_yaxis;
        string colums_yaxis2;
        int flag;
        public frmMAC_Equipment_Detail_State()
        {
            InitializeComponent();
        }
        public frmMAC_Equipment_Detail_State(DataTable dt, DataTable dt2, string xaxis, string yaxis, int flag_chart)
        {
            InitializeComponent();
            dataTable = dt;
            dataTable2 = dt2;
            colums_xaxis = xaxis;
            colums_yaxis = yaxis;
            flag = flag_chart;

        }
        private void frmMAC_Equipment_Detail_State_Load(object sender, EventArgs e)
        {
            try { base.InitButtons(); } catch { }//初始化标准功能，因要应用于RibbonForm，所以加入异常处理
            sbtnRefresh_Click(null, null);
        }
        public override void DoView(IButtonInfo sender)
        {
            sbtnRefresh_Click(null, null);
            base.DoView(sender);
        }
        public override void DoExport(IButtonInfo sender)
        {
            Common.ExportHelper exportHelper = new Common.ExportHelper();
            exportHelper.ExportToExcel(chartControl1, gridControl1, gridControl2, gridControl3);
            base.DoExport(sender);
        }
        public override void DoPrint(IButtonInfo sender)
        {
            Common.ExportHelper exportHelper = new Common.ExportHelper();
            exportHelper.PrintPreview(chartControl1, gridControl1, gridControl2, gridControl3);
            base.DoPrint(sender);
        }
        private void sbtnRefresh_Click(object sender, EventArgs e)
        {
            //显示右上表格
            ShowGridControl3();
            //显示左下表格
            ShowGridInfo(dataTable, dataTable2);
            //显示左上图表
            Common.ChartControlHelper.setData_Chart_Bar(chartControl1, dataTable2, colums_xaxis, colums_yaxis, flag);
        }
        private void ShowGridInfo(DataTable dt, DataTable dt2)
        {
            if (dt.Rows.Count > 0 && dt != null)
            {
                gridControl1.DataSource = dt;
                // gridView1.OptionsBehavior.Editable = false;
                gridView1.OptionsView.ColumnAutoWidth = true;
                gridView1.Appearance.HeaderPanel.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;

                ////设置页脚汇总
                //gridView1.OptionsView.ShowFooter = true;
                //gridView1.Columns[0].SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Count;
                //gridView1.Columns[0].SummaryItem.DisplayFormat = "合计：";           
                //gridView1.Columns[1].SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Sum;
                //gridView1.Columns[1].SummaryItem.DisplayFormat = "{0:N0}";

            }

        }

        private void rpLink_OpenLink(object sender, DevExpress.XtraEditors.Controls.OpenLinkEventArgs e)
        {
            if (gridView1.FocusedRowHandle != DevExpress.XtraGrid.GridControl.InvalidRowHandle)
            {
                int dataIndex = gridView1.GetDataSourceRowIndex(gridView1.FocusedRowHandle);
                string Machine_No = gridView1.GetRowCellDisplayText(dataIndex, "设备编号").ToString();       
                RefreshGridControl2(Machine_No);
            }
        }
        //未投产设备清单-Click事件
        private void RefreshGridControl2(string Machine_No)
        {
            Common.GetDataTable getData = new Common.GetDataTable();
            DataTable dataDetail = getData.GetREPORT_STATE_Detail(Machine_No);
            gridControl2.DataSource = dataDetail;
            gridView2.OptionsView.ColumnAutoWidth = true;
            gridView2.Appearance.HeaderPanel.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;

        }
        private void ShowGridControl3()
        {
            Common.GetDataTable getData = new Common.GetDataTable();
            DataTable data3 = getData.GetREPORT_STATE_Flow();
            gridControl3.DataSource = data3;
            gridView3.OptionsView.ColumnAutoWidth = true;
            gridView3.Appearance.HeaderPanel.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
        }

        private void frmMAC_Equipment_Detail_State_Resize(object sender, EventArgs e)
        {
            this.splitContainerControl1.SplitterPosition = splitContainerControl1.Width / 2;
            this.splitContainerControl2.SplitterPosition = splitContainerControl2.Width / 2;
        }
    }
}
